"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var login_service_1 = require("app/lib/service/login.service");
var local_storage_service_1 = require("../../lib/service/local-storage.service");
var oauth_service_1 = require("../../lib/service/oauth.service");
var LoginData = /** @class */ (function () {
    function LoginData() {
    }
    return LoginData;
}());
exports.LoginData = LoginData;
var LoginComponent = /** @class */ (function () {
    function LoginComponent(router, loginService, localStorageService) {
        this.router = router;
        this.loginService = loginService;
        this.localStorageService = localStorageService;
        this.loginData = new LoginData();
    }
    LoginComponent.prototype.ngOnInit = function () {
    };
    LoginComponent.prototype.login = function () {
        var _this = this;
        this.loginService.doLoginAdmin(this.username, this.password).subscribe(function (rs) {
            if (rs.code === 2000) {
                _this.loginData = rs;
                var time = new Date(rs.time);
                var now_time = time.getTime() / 1000;
                _this.loginData.data.user.time = now_time + '';
                // 清理之前登录的信息
                _this.localStorageService.clearAll();
                // 保存当前的信息
                _this.localStorageService.setAdminInfo(_this.loginData.data.user);
                _this.localStorageService.setToken(_this.loginData.data.token);
                return _this.redirect();
            }
            else {
                return _this.alerts = [{
                        type: 'danger',
                        msg: rs.message,
                    }];
            }
        }, function (err) { return console.log(err); });
    };
    LoginComponent.prototype.redirect = function () {
        // if (this.oauthService.isLogin()) {
        this.router.navigate(['/admin/category-manage/add-category']);
        console.log('已经登录');
        // this.router.navigate(['/admin/index']);
        // } else {
        //   console.log('未登录');
        // }
    };
    LoginComponent = __decorate([
        core_1.Component({
            selector: 'app-login',
            templateUrl: './login.component.html',
            styleUrls: ['./login.component.scss'],
            providers: [login_service_1.LoginService, oauth_service_1.OauthService, local_storage_service_1.LocalStorageService],
        })
    ], LoginComponent);
    return LoginComponent;
}());
exports.LoginComponent = LoginComponent;
